/*
 * @Author: dawei 664690250@qq.com
 * @Date: 2023-04-05 21:24:06
 * @LastEditors: dawei 664690250@qq.com
 * @LastEditTime: 2023-04-07 16:10:10
 * @FilePath: /hn-talent-ump-vue/src/services/schedule.js
 * @Description: 请填写文件描述
 * 大佬别走，带带弟弟
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
 */

import { axios } from '@/utils/request'
import { METHOD } from '@/store/mutation-types'
import { filterObj } from '@/utils/util'
const basicUrl = '/plan/schedule/content/v1'

// 新增计划节点
export function addPlanNode(parameter) {
  return axios({
    url: `${basicUrl}/add`,
    method: METHOD.POST,
    data: parameter
  })
}

// 更新计划节点
export function editPlanNode(parameter) {
  return axios({
    url: `${basicUrl}/edit`,
    method: METHOD.PUT,
    data: parameter
  })
}

// 删除计划节点
export function deletePlanNode(nodeId) {
  return axios({
    url: `${basicUrl}/remove/${nodeId}`,
    method: METHOD.DELETE
  })
}

// 获取计划节点列表
export function getPlanNodeList(schedulesId, pageNo = 1, pageSize = 10) {
  return axios({
    url: `${basicUrl}/page`,
    method: METHOD.GET,
    params: getQueryParams(schedulesId, pageNo, pageSize)
  })
}

// 获取计划看板数据
export function getPlanListWithContents(planYear) {
  return axios({
    url: `/plan/schedule/v1/listWithContents`,
    method: METHOD.GET,
    params: getPlanListParams(planYear)
  })
}

// 完成节点计划
export function accomplishNode(nodeId) {
  return axios({
    url: `${basicUrl}/accomplish/${nodeId}`,
    method: METHOD.PUT
  })
}

// 未完成节点计划
export function unaccomplishNode(nodeId) {
  return axios({
    url: `${basicUrl}/unaccomplished/${nodeId}`,
    method: METHOD.PUT
  })
}

// 新增节点附件
export function addAttach(parameter) {
  return axios({
    url: `${basicUrl}/attach/add`,
    method: METHOD.POST,
    data: parameter
  })
}

// 获取节点附件
export function getAttach(id) {
  return axios({
    url: `${basicUrl}/attach/${id}`,
    method: METHOD.GET
  })
}

// 删除节点附件
export function removeAttach(id) {
  return axios({
    url: `${basicUrl}/attach/remove/${id}`,
    method: METHOD.DELETE
  })
}

function getQueryParams(schedulesId, pageNo, pageSize) {
  const req = { 'criterions': [{ 'fieldName': 'schedulesId', 'operator': 'LIKE_START', 'value': schedulesId }], 'orders': [{ 'fieldName': 'createTime', 'desc': true }] }
  const param = { criteria: encodeURIComponent(JSON.stringify(req)) }
  param.pageNo = pageNo
  param.pageSize = pageSize
  return filterObj(param)
}
function getPlanListParams(planYear) {
  const req = { 'criterions': [{ 'fieldName': 'planYear', 'operator': 'LIKE_START', 'value': planYear }], 'orders': [{ 'fieldName': 'createTime', 'desc': true }] }
  const param = { criteria: encodeURIComponent(JSON.stringify(req)) }
  return filterObj(param)
}
